package com.itheima.demo1;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;
import java.util.Set;

public class HashMapDemo2 {
    public static void main(String[] args) {

        //定义一个数组存储景点
        String[] arr = {"A","B","C","D"};

        //利用随机存储将投票数存储下来
        ArrayList<String> list = new ArrayList<>();
        Random r = new Random();
        for (int i = 0; i < 80; i++) {
            int index = r.nextInt(arr.length);
            list.add(arr[index]);
        }


        //用map集合进行统计
        HashMap<String,Integer> hm = new HashMap<>();
        for (String s : list) {
            //判断当前景点是否存在
            if (hm.containsKey(s)){
                Integer count = hm.get(s);
                count++;
                hm.put(s,count);
            }else {
                hm.put(s,1);
            }
        }
        System.out.println(hm);
        int max = 0;
        Set<String> strings = hm.keySet();
        for (String string : strings) {
            Integer s = hm.get(string);
            max = max>s ? max : s ;
        }
        for (String string : strings) {
            Integer s = hm.get(string);
            if (s == max){
                System.out.println(string);
            }
        }
        System.out.println(max);

    }
}
